pipeline {
    agent any
    stages {
<#if mode == "multistage">
    <#if sedScript != "">
        stage("sed") {
            steps {
                ${sedScript}
            }
        }
    </#if>
<#else>
        stage("build") {
            steps {
                ${sedScript}
                // mvn-build.sh {moduleName}
                sh 'mvn-build.sh ${moduleName}'
            }
        }
</#if>
        stage("docker") {
            steps {
<#if mode == "multistage">
                sh 'cp -f /usr/local/bin/apache-maven-3.8.3/conf/settings.xml .'
</#if>
                // Usage: docker-build-with-dockerfile.sh {imageName} {extraTag} {workdir}
                sh 'docker-build-with-dockerfile.sh ${imageName} ${extraTag} ${workDir}'
            }
        }
        
        stage("deploy") {
            steps {
                // Usage deploy-v2.sh {cluster} {env} {yamlfile}
                sh 'deploy-v2.sh ${cluster} ${env} ${yamlFile}'
            }
        }
        stage("check") {
            steps {
                // Usage check.sh {cluster} {deployName} {namespace}
                // sh 'check-v2.sh ${cluster} ${deploymentName} ${namespace}'
                sh 'k8s-cmd check --kubeconfig ${kubeconfig} -n ${namespace} -a ${deploymentName} -i ${allImageName} -T `cat .tag`'
            }
        }
    }
    post {
        success {
            // Usage remind-v2.py {cluster} 1 {msg}
            sh 'remind-v2.py ${cluster} 1 ${msg}'
        }
        failure {
            // Usage remind-v2.py {cluster} 0 {msg}
            sh 'remind-v2.py ${cluster} 0 ${msg}'
        }
    }
}
